package com.pe1n.yangtaopai.presenter;

import android.util.Log;

import com.pe1n.yangtaopai.bean.TwoTwoBean;
import com.pe1n.yangtaopai.modle.ModeItemTwo;
import com.pe1n.yangtaopai.view.interfacese.IViewIntemTwo;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2016/11/28.
 */

public class PresenterIntemTwo implements IPresenterIntemTwo {
    private ModeItemTwo mModeItemTwo;
    private IViewIntemTwo iViewIntemTwo;

    public PresenterIntemTwo(IViewIntemTwo iViewIntemTwo) {
        this.mModeItemTwo = new ModeItemTwo();
        this.iViewIntemTwo = iViewIntemTwo;
    }

    @Override
    public void LoadItemTwoTwoData(String urlString) {
        Log.e("TAG", "--------------------------" + urlString);
        mModeItemTwo.getTwoTwoBEAN(urlString)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<TwoTwoBean>() {
                    @Override
                    public void onCompleted() {
                        iViewIntemTwo.showProgress();
                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.e("tag", e.getMessage());

                    StackTraceElement[] st=    e.getStackTrace();
                        for (StackTraceElement  ste: st) {
                            Log.e("tag",ste.toString());
                        }

                    }

                    @Override
                    public void onNext(TwoTwoBean twoTwoBean) {
                        iViewIntemTwo.LoadItemListTwoData(twoTwoBean);
                    }
                });
    }
}
